﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using StarTrek.World;

namespace StarTrek.UI.Console.MenuItem
{
    class MenuImpulse:iMenuItem
    {
        private const string ACTION_KEY = "I";
        #region iMenuItem Members

        public bool ProcessSomeRequest(MenuContext Menu, TextWriter sw, TextReader tr)
        {
            bool rVal = (Menu.Action == MenuAction);

            if (rVal)
            {
                Galaxy theWorld = Galaxy.Instance;
                sw.Write(Menu.wordWrap(Properties.Resources.MenuImpulsePrompt + Properties.Resources.MenuPrompt));
                string results = tr.ReadLine();
                SectorPoint sector = SectorPoint.ParseVector(results);

                try
                {
                    theWorld.CurrentShip.Travel(theWorld.CurrentShip.CurrentLocation.Parent.GetSpaceItem(sector.X,
                                                                                                         sector.Y));
                }catch(InvalidFlightPath ex)
                {
                    sw.WriteLine(Menu.wordWrap(Properties.Resources.MenuImpulseError));
                }

            }
            return rVal;
        }

        public string MenuAction
        {
            get { return ACTION_KEY; }
        }

        public string Text
        {
            get { return Properties.Resources.MenuImpulseText; }
        }

        public string VerboseText
        {
            get { return Properties.Resources.MenuImpulseVebose; }
        }

        #endregion
    }
}
